const Koa = require('koa');

const logger = require('koa-logger')
const app = new Koa();

app.use(logger());
app.use( async(ctx) => {
    let url = ctx.url;

    // 从request中获取GET请求
    let request = ctx.request;

    let req_query = request.query;

    let req_querystring = request.querystring;


    // 从上下文中直接获取

    let ctx_query = ctx.query

    let ctx_querystring = ctx.querystring
    
    ctx.body = {
        url,

        req_query,  // 返回格式好的参数对象

        req_querystring, // 返回请求字符串

        ctx_query,
        
        ctx_querystring

    }
})

app.listen(3000, () => {
    console.log('koa server starting at demo1.js')
})

